# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=libblockdev
pkgver=3.0.4
pkgrel=1
pkgdesc="A library for manipulating block devices"
arch=('loong64' 'x86_64')
url="https://github.com/storaged-project/libblockdev"
license=(LGPL-2.1-or-later)
depends=(
  'cryptsetup'
  'device-mapper'
  'e2fsprogs'
  'gcc-libs'
  'glib2'
  'glibc'
  'kmod'
  'keyutils'
  'libbytesize'
  'libnvme'
  'mdadm'
  'nss'
  'parted'
  'systemd-libs'
  'util-linux-libs'
  'volume_key'
)
makedepends=(
  'autoconf-archive'
  'gobject-introspection'
  'gtk-doc'
  'ndctl'
  'python'
  'util-linux'
)
optdepends=(
  'btrfs-progs: BTRFS plugin'
  'dosfstools: VFAT filesystem support'
  'exfatprogs: for exFAT filesystem support'
  'f2fs-tools: for F2FS filesystem support'
  'gobject-introspection-runtime: for Python integration'
  'lvm2: LVM plugin'
  'ndctl: NVDIMM plugin'
  'nilfs-utils: for nilfs filesystem support'
  'ntfs-3g: NTFS filesystem support'
  'python: for Python integration'
  'udftools: for UDF filesystem support'
  'xfsprogs: XFS filesystem support'
)
source=(
  "https://github.com/storaged-project/libblockdev/releases/download/$pkgver-1/libblockdev-$pkgver.tar.gz"
)
sha512sums=('82b574c1f8e301d6e9ff07f8c3d2a351a5bc966b5d65a3b578c214e03e48b54270b54176d646ac15e8119c79536d08b36415de478ffd34c8b3fe536300fc5172')
b2sums=('e31ecb04310c2c66cbe432c1e003b3c3241f318f78916d5c61c0efca37fa677e5f857eab9b7c3bfc7c5a589350cdef12402940d28af68ab9fc95e5da6852ddf1')

build() {
  local configure_options=(
    --prefix=/usr
    --sysconfdir=/etc
    --without-bcache
    --without-lvm_dbus
    --without-mpath
  )

  cd $pkgname-$pkgver
  ./configure "${configure_options[@]}"
  # prevent libtool from overlinking everything
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

check() {
  cd $pkgname-$pkgver
  make check
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install
}
